package com.lib.controller.admin;

import com.lib.pojo.DTO.PageDTO;
import com.lib.pojo.DTO.RecommendAddBooksDTO;
import com.lib.pojo.DTO.RecommendDTO;
import com.lib.pojo.DTO.RecommendPageDTO;
import com.lib.pojo.VO.RcommendVO;
import com.lib.pojo.entity.PageResult;
import com.lib.pojo.entity.Result;
import com.lib.service.RecommendService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("AdminRecommendController")
@Slf4j
@Tag(name = "图书套餐接口")
@RequestMapping("/admin/recommends")
@CrossOrigin(origins = "*")
public class RecommendController {
    @Autowired
    private RecommendService recommendService;


    /**
     * 根据套餐ID查询图书
     *
     * @param recommendId 套餐ID
     * @return 图书列表
     */
    @GetMapping("/recommendId")
    @Operation(summary = "根据套餐ID查询图书")
    public Result<List<RcommendVO>> getRecommend(Integer recommendId) {
        log.info("根据套餐ID查询图书: {}", recommendId);
        List<RcommendVO> rcommendVOS = recommendService.getRecommendById(recommendId);
        return Result.success(rcommendVOS);
    }
    
    /**
     * 根据套餐ID删除套餐
     * @param recommendId 套餐ID
     * @return 操作结果
     */
    @DeleteMapping("/{recommendId}")
    @Operation(summary = "根据套餐ID删除套餐")
    public Result deleteById(@PathVariable Integer recommendId) {
        log.info("根据套餐ID删除套餐: {}", recommendId);
        recommendService.deleteById(recommendId);
        return Result.success();
    }
    
    /**
     * 根据套餐ID查询套餐信息
     *
     * @param recommendId 套餐ID
     * @return 套餐信息
     */
    @GetMapping("/info/recommendId")
    @Operation(summary = "根据套餐ID查询套餐信息")
    public Result<List<RcommendVO>> getRecommendInfo(Integer recommendId) {
        log.info("根据套餐ID查询套餐信息: {}", recommendId);
        List<RcommendVO> recommendVOS = recommendService.getRecommendInfoById(recommendId);
        return Result.success(recommendVOS);
    }
    /**
     * 启用、禁用套餐
     * @param status 状态（0:禁用，1:启用）
     * @param recommendId 套餐ID
     * @return 操作结果
     */
    @Operation(summary = "启用、禁用套餐")
    @PostMapping("/status/{status}")
    public Result statusStartOrStop(@PathVariable Integer status,  Integer recommendId){
        log.info("启用、禁用套餐，状态:{}, 套餐ID:{}", status, recommendId);
        recommendService.statusStartOrStop(status, recommendId);
        return Result.success();
    }

    /**
     * 新增套餐
     * @param recommendAddBooksDTO 套餐信息
     * @return 操作结果
     */
    @PostMapping
    @Operation(summary = "新增套餐")
    public Result addRecommend(@RequestBody RecommendAddBooksDTO recommendAddBooksDTO) {
        log.info("新增套餐 {}",recommendAddBooksDTO);
        recommendService.addRecommend(recommendAddBooksDTO);
        return Result.success();
    }

    /**
     * 修改套餐
     * @param recommendAddBooksDTO 套餐信息
     * @return 操作结果
     */
    @Operation(summary = "修改套餐")
    @PutMapping
    public Result PutRecommend(@RequestBody RecommendAddBooksDTO recommendAddBooksDTO) {
        log.info("修改套餐 {}",recommendAddBooksDTO);
        recommendService.putRecommend(recommendAddBooksDTO);
        return Result.success();
    }
    //套餐分页查询
    @Operation(summary = "套餐分页查询")
    @PostMapping("/page")
    public Result<PageResult> page(@RequestBody RecommendPageDTO recommendPageDTO) {
        log.info("套餐分页查询 {}",recommendPageDTO);
        PageResult pageResult = recommendService.page(recommendPageDTO );
        return Result.success(pageResult);
    }
    // 批量删除
    @Operation(summary = "批量删除")
    @DeleteMapping("/ids")
    public Result delete(@RequestParam("ids") List<Integer> ids) {
        log.info("批量删除 {}", ids);
        recommendService.delete(ids);
        return Result.success();
    }
//    //删除关联的图书id和套餐id
//    @Operation(summary = "删除关联的图书id和套餐id")
//    @DeleteMapping("/deleteById")
//    public Result deleteByRecommendId(Integer recommendId) {
//        log.info("删除关联的图书 {}", recommendId);
//        recommendService.deleteByRecommendId(recommendId);
//        return Result.success();
//    }


}
